(function(){
  'use strict';

  if (window.UI) return;

  function el(tag, props, children){
    var e = document.createElement(tag);
    if (props){ for (var k in props){ if (k==='className') e.className=props[k]; else if (k==='text') e.textContent=props[k]; else e.setAttribute(k, props[k]); } }
    if (children){ for (var i=0;i<children.length;i++) e.appendChild(children[i]); }
    return e;
  }

  function show(el, yes){ if (!el) return; el.classList.toggle('is-hidden', !yes); el.style.display = yes ? '' : el.style.display; }

  function copyToClipboard(text){
    if (navigator.clipboard && navigator.clipboard.writeText) return navigator.clipboard.writeText(text);
    return new Promise(function(resolve){
      var ta = document.createElement('textarea'); ta.value = text; document.body.appendChild(ta); ta.select(); try { document.execCommand('copy'); } catch(_) {} document.body.removeChild(ta); resolve();
    });
  }

  function fmtDate(s){ var d=new Date(s); if (isNaN(d.getTime())) return String(s||''); return d.toISOString().replace('T',' ').replace(/\.\d{3}Z$/,''); }

  window.UI = { el: el, show: show, copyToClipboard: copyToClipboard, fmtDate: fmtDate };
})();


